package com.htandroid.htandroid.aty;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.ab.activity.AbActivity;
import com.ab.fragment.AbLoadDialogFragment;
import com.ab.model.AbMenuItem;
import com.ab.soap.AbSoapListener;
import com.ab.soap.AbSoapParams;
import com.ab.soap.AbSoapUtil;
import com.ab.util.AbDialogUtil;
import com.ab.util.AbToastUtil;
import com.ab.view.ioc.AbIocView;
import com.ab.view.pullview.AbPullToRefreshView;
import com.ab.view.titlebar.AbTitleBar;
import com.htandroid.htandroid.R;
import com.htandroid.htandroid.adapter.ListPopAdapter;
import com.htandroid.htandroid.entity.UffjqgdList;
import com.htandroid.htandroid.entity.UffjqgdList_detail;
import com.htandroid.htandroid.entity.Vendor;
import com.htandroid.htandroid.global.MyApplication;
import com.htandroid.htandroid.sys.Basenvo;
import com.htandroid.htandroid.sys.InstorageURL;
import com.htandroid.htandroid.sys.User;
import com.htandroid.htandroid.webservice.BuildQgdDjdetailXMLService;
import com.htandroid.htandroid.webservice.XMLQgdDjdetail;
import com.htandroid.htandroid.webservice.abXMLQgdDjdetail;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import static com.htandroid.htandroid.constance.ConstanceServer.BaseUrl_New;

/**
 * Created by lkp on 2015/12/4.
 */
public class qgddj_detail extends AbActivity implements
        AbPullToRefreshView.OnHeaderRefreshListener, AbPullToRefreshView.OnFooterLoadListener {
    public MyApplication myApplication;
    private ArrayList<UffjqgdList_detail> qgdlist_detail;
    private int icurrentrow;
    private UffjqgdList qgdtitle;
    private UffjqgdList_detail qgds;
    int textcolor_old;
    private ArrayList<Vendor> venlist;
    private String listtype = "0";
    private AbTitleBar mAbTitleBar = null;
    private View rightView1 = null;
    private View rightView2 = null;
    private View rightView3 = null;
    private TextView tv_currentrow;

    private AbLoadDialogFragment mDialogFragment = null;
    private PopupWindow popupWindow;
    private ListView popListView;
    private View popView;

    @AbIocView(id = R.id.iquantity_tv)
    EditText iquantity_tv;
    @AbIocView(id = R.id.cven_tv)
    EditText cven_tv;
    @AbIocView(id = R.id.iprice_et)
    EditText iprice_et;
    @AbIocView(id = R.id.cven1_et)
    EditText cven1_et;
    @AbIocView(id = R.id.iamount_tv)
    EditText iamount_tv;
    @AbIocView(id = R.id.iprice1_et)
    EditText iprice1_et;
    @AbIocView(id = R.id.cven2_et)
    EditText cven2_et;
    @AbIocView(id = R.id.iprice2_et)
    EditText iprice2_et;
    @AbIocView(id = R.id.cven3_et)
    EditText cven3_et;
    @AbIocView(id = R.id.iprice3_et)
    EditText iprice3_et;
    @AbIocView(id = R.id.cven_iv)
    ImageView cven_iv;
    @AbIocView(id = R.id.cven_iv1)
    ImageView cven_iv1;
    @AbIocView(id = R.id.cven_iv2)
    ImageView cven_iv2;
    @AbIocView(id = R.id.cven_iv3)
    ImageView cven_iv3;
    @AbIocView(id = R.id.tv_djhis, click = "btnClick")
    TextView tv_djhis;
    @AbIocView(id = R.id.tv_djxy, click = "btnClick")
    TextView tv_djxy;
    @AbIocView(id = R.id.tv_tempsave, click = "btnClick")
    TextView tv_tempsave;
    @AbIocView(id = R.id.tv_save, click = "btnClick")
    TextView tv_save;
    @AbIocView(id = R.id.tv_undo, click = "btnClick")
    TextView tv_undo;
    @AbIocView(id = R.id.cinvname_tv)
    TextView cinvname_tv;
    @AbIocView(id = R.id.cinvunit_tv)
    TextView cinvunit_tv;
    @AbIocView(id = R.id.cinvstd_tv)
    TextView cinvstd_tv;
    @AbIocView(id = R.id.iqgq_tv)
    TextView iqgq_tv;
    @AbIocView(id = R.id.mPullRefreshView)
    AbPullToRefreshView mAbPullToRefreshView;
    @AbIocView(id = R.id.bapprove_rg)
    RadioGroup bapprove_rg;

    /**
     * ATTENTION: This was auto-generated to implement the App Indexing API.
     * See https://g.co/AppIndexing/AndroidStudio for more information.
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setAbContentView(R.layout.layout_qgddj_detail);
        initview();
    }

    @Override
    public void onFooterLoad(AbPullToRefreshView view) {
        refreshTask();
    }

    @Override
    public void onHeaderRefresh(AbPullToRefreshView view) {
        refreshTask();
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    public void onPause() {
        super.onPause();
    }

    public void btnClick(View v) {
        if (listtype.equals("0")) {
            switch (v.getId()) {
                case R.id.tv_djhis:
                    qgddj_his(v);
                    break;
                case R.id.tv_djxy:
                    qgddj_xy(v);
                    break;
                case R.id.tv_tempsave:
                    qgddj_tempsave(v);
                    break;
                case R.id.tv_save:
                    qgddj_save(v);
                    break;
            }
        } else {
            switch (v.getId()) {
                case R.id.tv_undo:
                    qgddj_undj(v);
                    break;
            }
        }
    }

    //初始化
    private void initview() {
        myApplication = (MyApplication) abApplication;//获得我们的应用程序全局变量
        mAbTitleBar = this.getTitleBar();
        mAbTitleBar.setTitleText("部门定价明细");
        mAbTitleBar.setLogo(R.drawable.icon_back);
        mAbTitleBar.getLogoView().setLayoutParams(new LinearLayout.LayoutParams(58, 57));
        mAbTitleBar.getLogoView().setFocusable(true);
        mAbTitleBar.getLogoView().setFocusableInTouchMode(true);
        mAbTitleBar.setTitleBarBackground(R.color.common_title);
        mAbTitleBar.setTitlePadding(118, 0, 0, 0);

        mAbTitleBar.clearRightView();
        rightView1 = mInflater.inflate(R.layout.btn_abs_back, null);
        mAbTitleBar.addRightView(rightView1);
        rightView2 = mInflater.inflate(R.layout.tv_currentrow, null);
        mAbTitleBar.addRightView(rightView2);
        rightView3 = mInflater.inflate(R.layout.btn_abs_forward, null);
        mAbTitleBar.addRightView(rightView3);
        tv_currentrow = (TextView) rightView2.findViewById(R.id.tv_currentrow);
        tv_currentrow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                more_list(v);
            }
        });

        // 设置监听器
        mAbPullToRefreshView.setOnHeaderRefreshListener(this);
        mAbPullToRefreshView.setOnFooterLoadListener(this);
        // 设置进度条的样式
        mAbPullToRefreshView.getHeaderView().setHeaderProgressBarDrawable(
                this.getResources().getDrawable(R.drawable.progress_circular));
        mAbPullToRefreshView.getFooterView().setFooterProgressBarDrawable(
                this.getResources().getDrawable(R.drawable.progress_circular));
        // 显示进度框
//        mDialogFragment = AbDialogUtil.showLoadDialog(this, R.layout.view_dialog_loading, "正在加载...");
//        mDialogFragment.setAbDialogOnLoadListener(new AbDialogFragment.AbDialogOnLoadListener() {
//
//            @Override
//            public void onLoad() {
//                refreshTask();
//            }
//        });

        //读取文本颜色
        textcolor_old = iquantity_tv.getCurrentTextColor();
        //进入窗口时,所有控件处于不可编辑状态,下拉隐藏
        showwin(false);
        //获取传递的对象参数
        qgdtitle = (UffjqgdList) getIntent().getSerializableExtra("uffjqgds");
        refreshTask();
        listtype = getIntent().getExtras().getString("listtype");

        //单价修改的监听
        iprice_et.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId,
                                          KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    String iquantity = iquantity_tv.getText().toString();
                    String iprice = iprice_et.getText().toString();
                    if (iquantity == null || iquantity.equals("") || iprice.equals("")) {
                        iamount_tv.setText(Basenvo.customFormat("#####0.00##", "0"));
                    } else {
                        iamount_tv.setText(Basenvo.customFormat("#####0.00##", Double.valueOf(iquantity) * Double.valueOf(iprice)));
                    }
                }
                return false;
            }
        });

        //单价焦点变化
        iprice_et.setOnFocusChangeListener(new android.view.View.
                OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    // 此处为得到焦点时的处理内容
                } else {
                    String iquantity = iquantity_tv.getText().toString();
                    String iprice = iprice_et.getText().toString();
                    if (iquantity == null || iquantity.equals("") || iprice.equals("")) {
                        iamount_tv.setText(Basenvo.customFormat("#####0.00##", "0"));
                    } else {
                        iamount_tv.setText(Basenvo.customFormat("#####0.00##", Double.valueOf(iquantity) * Double.valueOf(iprice)));
                    }
                }
            }
        });

        //通过数量修改的监听
        iquantity_tv.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId,
                                          KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    String iquantity = iquantity_tv.getText().toString();
                    String iprice = iprice_et.getText().toString();
                    if (iquantity == null || iquantity.equals("") || iprice.equals("")) {
                        iamount_tv.setText(Basenvo.customFormat("#####0.00##", "0"));
                    } else {
                        iamount_tv.setText(Basenvo.customFormat("#####0.00##", Double.valueOf(iquantity) * Double.valueOf(iprice)));
                    }
                }
                return false;
            }
        });

        //通过数量焦点变化
        iquantity_tv.setOnFocusChangeListener(new android.view.View.
                OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    // 此处为得到焦点时的处理内容
                } else {
                    String iquantity = iquantity_tv.getText().toString();
                    String iprice = iprice_et.getText().toString();
                    if (iquantity == null || iquantity.equals("") || iprice.equals("")) {
                        iamount_tv.setText(Basenvo.customFormat("#####0.00##", "0"));
                    } else {
                        iamount_tv.setText(Basenvo.customFormat("#####0.00##", Double.valueOf(iquantity) * Double.valueOf(iprice)));
                    }
                }
            }
        });

        if (listtype.equals("0")) {
            //隐藏取消定价
            tv_undo.setVisibility(View.GONE);
        } else {
            //其他按钮隐藏
            tv_djhis.setVisibility(View.GONE);
            tv_djxy.setVisibility(View.GONE);
            tv_tempsave.setVisibility(View.GONE);
            tv_save.setVisibility(View.GONE);
        }

        popView = mInflater.inflate(R.layout.list_pop, null);
        popListView = (ListView) popView.findViewById(R.id.pop_list);
        popupWindow = new PopupWindow(popView, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, true);
        popupWindow.setTouchable(true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        AnimationSet animationSet = new AnimationSet(true);
        ScaleAnimation scaleAnimation = new ScaleAnimation(0, 1, 1, 1, Animation.ZORDER_BOTTOM, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        animationSet.setDuration(250);
        animationSet.addAnimation(scaleAnimation);
        popView.startAnimation(animationSet);
        ImageView more_close = (ImageView) popView.findViewById(R.id.item_close);
        more_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popupWindow.dismiss();
            }
        });
        ImageView titlemore_iv = (ImageView) findViewById(R.id.titlemore_iv);
        titlemore_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final ImageView img = (ImageView) v;
                //构造数据
                Map<AbMenuItem, AbMenuItem> map1 = new HashMap<AbMenuItem, AbMenuItem>();
                Map<AbMenuItem, AbMenuItem> map2 = new HashMap<AbMenuItem, AbMenuItem>();
                Map<AbMenuItem, AbMenuItem> map3 = new HashMap<AbMenuItem, AbMenuItem>();
                Map<AbMenuItem, AbMenuItem> map4 = new HashMap<AbMenuItem, AbMenuItem>();
                Map<AbMenuItem, AbMenuItem> map5 = new HashMap<AbMenuItem, AbMenuItem>();
                Map<AbMenuItem, AbMenuItem> map6 = new HashMap<AbMenuItem, AbMenuItem>();
                Map<AbMenuItem, AbMenuItem> map7 = new HashMap<AbMenuItem, AbMenuItem>();
                map1.put(new AbMenuItem("　单据号："), new AbMenuItem(qgdtitle.getCvouchid()));
                map2.put(new AbMenuItem("请购日期："), new AbMenuItem(qgdtitle.getDdate()));
                map3.put(new AbMenuItem("请购部门："), new AbMenuItem(qgdtitle.getCdepname()));
                map4.put(new AbMenuItem("请购类别："), new AbMenuItem(qgdtitle.getCqgtype()));
                map5.put(new AbMenuItem("审批流程："), new AbMenuItem(qgdtitle.getLinename()));
                if (qgdtitle.getCprechecker().equals("") && !qgdtitle.getCprecheckertemp().equals("")) {
                    map6.put(new AbMenuItem("　暂存人："), new AbMenuItem(qgdtitle.getCprecheckertemp()));
                } else {
                    map6.put(new AbMenuItem("　定价人："), new AbMenuItem(qgdtitle.getCprechecker()));
                    map7.put(new AbMenuItem("定价时间："), new AbMenuItem(Basenvo.customDateFormat("yyyy-MM-dd", qgdtitle.getCprecheckdate())));
                }
                ArrayList<Map<AbMenuItem, AbMenuItem>> data = new ArrayList<Map<AbMenuItem, AbMenuItem>>();
                data.add(map1);
                data.add(map2);
                data.add(map3);
                data.add(map4);
                data.add(map5);
                data.add(map6);
                data.add(map7);
                ListPopAdapter mListPopAdapter = new ListPopAdapter(qgddj_detail.this, data, R.layout.list_popitem);
                popListView.setAdapter(mListPopAdapter);

                //弹出窗口后,变更更多图标
                img.setImageResource(R.drawable.item_more_choose);
                popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                    public void onDismiss() {
                        //还原图标
                        img.setImageResource(R.drawable.item_more);
                    }
                });
                popupWindow.showAsDropDown(v);
            }
        });
    }

    public void refreshTask() {
        //参数
        String urlString = "http://" + InstorageURL.SERVERURL + BaseUrl_New;//旧版webservice地址
        AbSoapParams params = new AbSoapParams();
        params.put("arg0", myApplication.getGs_ztid());
        params.put("arg1", myApplication.getGs_year());
        params.put("arg2", qgdtitle.getCvouchid());
        params.put("arg3", qgdtitle.getIinorder());
        mAbSoapUtil.call(urlString, InstorageURL.NAME_SPACE, "qgddj_detaillist", params, new AbSoapListener() {
            //获取数据成功会调用这里
            @Override
            public void onSuccess(int statusCode, String content) {
                if (content != null) {
                    qgdlist_detail = abXMLQgdDjdetail.paraseCommentInfors(content);
                    if (qgdlist_detail.size() > 0) {
                        insert_data(0);
                    }
                } else {
                    AbToastUtil.showToast(qgddj_detail.this, R.string.sqlerrormsg);
                }
                AbDialogUtil.removeDialog(qgddj_detail.this);
            }

            // 失败，调用
            @Override
            public void onFailure(int statusCode, String content,
                                  Throwable error) {
                AbToastUtil.showToast(qgddj_detail.this, R.string.sqlerrormsg);
            }

            // 开始执行前
            @Override
            public void onStart() {
                //显示进度框
                AbDialogUtil.showProgressDialog(qgddj_detail.this, 0, "正在加载...");
            }


            // 完成后调用，失败，成功
            @Override
            public void onFinish() {
                //移除进度框
                AbDialogUtil.removeDialog(qgddj_detail.this);
            }
        });
        mAbPullToRefreshView.onHeaderRefreshFinish();

        //参数
//                String[] parms = {"cacc_id", "iyear", "cvouchid", "iinorder"};
//                String[] vals = {myApplication.getGs_ztid(), myApplication.getGs_year(), qgdtitle.getCvouchid(), qgdtitle.getIinorder()};
//                //生成xml
//                BuildQgdListXMLService service = new BuildQgdListXMLService();
//                String xmlstring = service.buildXML(null, "qgddj_detaillist", InstorageURL.NAME_SPACE, parms, vals, null);
//                ToolSOAPxml.callService("qgddj_detaillist", xmlstring, new ToolSOAPxml.WebServiceCallBack() {
//                    @Override
//                    public void onSucced(String result) {
//                        ToolLog.log("11111111-------------result:" + result);
//                        if (result != null) {
//                            //解析xml文件,返回列表
//                            qgdlist_detail = XMLQgdDjdetail.paraseCommentInfors(result);
//                            //默认显示第一行数据
//                            if (qgdlist_detail.size() > 0) {
//                                insert_data(0);
//                            }
//                        } else {
//                            Toast.makeText(getApplicationContext(), "数据库返回信息错误", Toast.LENGTH_SHORT).show();
//                        }
//                        loadingDialog.loadingfinish();
//                    }
//
//                    @Override
//                    public void onFailure(String result) {
//                        loadingDialog.loadingfinish();
//                        Toast.makeText(getApplicationContext(), "数据库返回信息错误", Toast.LENGTH_SHORT).show();
//                    }
//                });
    }

    //为窗口填充数据
    public void insert_data(int listrow) {
        if (listtype.equals("0")) {
            //未定价时,默认进入的就是修改状态。经过测试，发现之前的操作模式太过繁琐
            showwin(true);
        } else {
            showwin(false);
        }
        qgds = qgdlist_detail.get(listrow);
        icurrentrow = listrow;
        //填充数据
        //行号
        tv_currentrow.setText((icurrentrow + 1) + "/" + (qgdlist_detail.size()));

        //不可修改部分
        cinvname_tv.setText(qgds.getCinvname());
        cinvunit_tv.setText(qgds.getCinvm_unit());
        cinvstd_tv.setText(qgds.getCinvstd());
        iqgq_tv.setText(Basenvo.customFormat("#####0.00##", qgds.getIqgq()));

        //可修改部分
        iquantity_tv.setText(Basenvo.customFormat("#####0.00##", qgds.getIquantity()));
        cven_tv.setText("" + qgds.getCvenname());
        cven_tv.setTag("" + qgds.getCvencode());
        iprice_et.setText(Basenvo.customFormat("#####0.00##", qgds.getIprice()));
        iamount_tv.setText(Basenvo.customFormat("#####0.00##", qgds.getIamount()));
        cven1_et.setText(qgds.getCvennamep1());
        cven1_et.setTag(qgds.getCvencodep1());
        iprice1_et.setText(Basenvo.customFormat("#####0.00##", qgds.getIpricep1()));
        cven2_et.setText(qgds.getCvennamep2());
        cven2_et.setTag(qgds.getCvencodep2());
        iprice2_et.setText(Basenvo.customFormat("#####0.00##", qgds.getIpricep2()));
        cven3_et.setText(qgds.getCvennamep3());
        cven3_et.setTag(qgds.getCvencodep3());
        iprice3_et.setText(Basenvo.customFormat("#####0.00##", qgds.getIpricep3()));
        //
        if (Basenvo.equal(qgds.getBapprove(), "0")) {
            bapprove_rg.check(R.id.no_rb);
        } else {
            bapprove_rg.check(R.id.yes_rb);
        }
        //数据填充完成后,根据信息修改字体颜色
        //根据定价方式和是否修改变化字体颜色
        if (!Basenvo.equal(qgds.getIprice(), qgds.getDjprice()) || Basenvo.equal(qgds.getDjtype(), "0")) {
            iprice_et.setTextColor(Color.RED);
        } else {
            if (Basenvo.equal(qgds.getDjtype(), "1") || Basenvo.equal(qgds.getDjtype(), "2")) {
                iprice_et.setTextColor(textcolor_old);
            } else {
                if (Basenvo.equal(qgds.getDjtype(), "3")) {
                    iprice_et.setTextColor(Color.WHITE);
                } else {
                    iprice_et.setTextColor(Color.RED);
                }
            }
        }
        //根据定价方式和是否修改变化字体颜色
        if (!qgds.getCvencode().equals(qgds.getDjcvencode())) {
            cven_tv.setTextColor(Color.RED);
        } else {
            if (qgds.getDjtype().equals("1") || qgds.getDjtype().equals("2")) {
                cven_tv.setTextColor(textcolor_old);

            } else {
                if (qgds.getDjtype().equals("3")) {
                    cven_tv.setTextColor(Color.WHITE);
                } else {
                    cven_tv.setTextColor(Color.RED);
                }
            }
        }
        //判断有没有修改供应商的权限
        if (!qgds.getBinvtype().equals("1") && !qgds.getBapprove().equals("0") && !qgds.getBclose().equals("1")) {
            //禁止选择
            if (!((!qgds.getDjtype().equals("1") && !qgds.getDjtype().equals("2")) || myApplication.authfind("QG0002"))) {
                //禁止选择,隐藏下拉按钮
                cven_iv.setVisibility(View.GONE);
                cven_iv1.setVisibility(View.GONE);
                cven_iv2.setVisibility(View.GONE);
                cven_iv3.setVisibility(View.GONE);

                cven2_et.setBackgroundColor(Color.TRANSPARENT);
                cven1_et.setEnabled(false);
                cven1_et.setBackgroundColor(Color.TRANSPARENT);

                cven2_et.setEnabled(false);
                cven2_et.setBackgroundColor(Color.TRANSPARENT);
                cven3_et.setEnabled(false);
                cven3_et.setBackgroundColor(Color.TRANSPARENT);

                iprice_et.setEnabled(false);
                iprice_et.setBackgroundColor(Color.TRANSPARENT);
                iprice1_et.setEnabled(false);
                iprice1_et.setBackgroundColor(Color.TRANSPARENT);
                iprice2_et.setEnabled(false);
                iprice2_et.setBackgroundColor(Color.TRANSPARENT);
                iprice3_et.setEnabled(false);
                iprice3_et.setBackgroundColor(Color.TRANSPARENT);
            } else {
                if (!myApplication.authfind("QG0001")) {
                    iprice_et.setEnabled(false);
                    iprice_et.setBackgroundColor(Color.TRANSPARENT);
                    iprice1_et.setEnabled(false);
                    iprice1_et.setBackgroundColor(Color.TRANSPARENT);
                    iprice2_et.setEnabled(false);
                    iprice2_et.setBackgroundColor(Color.TRANSPARENT);
                    iprice3_et.setEnabled(false);
                    iprice3_et.setBackgroundColor(Color.TRANSPARENT);
                }
            }
        } else {
            //禁止选择
            cven_iv.setVisibility(View.GONE);
            cven_iv1.setVisibility(View.GONE);
            cven_iv2.setVisibility(View.GONE);
            cven_iv3.setVisibility(View.GONE);

            cven1_et.setEnabled(false);
            cven1_et.setBackgroundColor(Color.TRANSPARENT);
            cven2_et.setEnabled(false);
            cven2_et.setBackgroundColor(Color.TRANSPARENT);
            cven3_et.setEnabled(false);
            cven3_et.setBackgroundColor(Color.TRANSPARENT);
            iprice_et.setEnabled(false);
            iprice_et.setBackgroundColor(Color.TRANSPARENT);
            iprice1_et.setEnabled(false);
            iprice1_et.setBackgroundColor(Color.TRANSPARENT);
            iprice2_et.setEnabled(false);
            iprice2_et.setBackgroundColor(Color.TRANSPARENT);
            iprice3_et.setEnabled(false);
            iprice3_et.setBackgroundColor(Color.TRANSPARENT);
        }
        //写入明细的扩展信息
        insert_data_detail();
    }

    public void insert_data_detail() {
        //存货扩展信息弹窗
        ImageView listmore_iv = (ImageView) findViewById(R.id.listmore_iv);
        listmore_iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                final ImageView imgs = (ImageView) v;
                Map<AbMenuItem, AbMenuItem> map1 = new HashMap<AbMenuItem, AbMenuItem>();
                Map<AbMenuItem, AbMenuItem> map2 = new HashMap<AbMenuItem, AbMenuItem>();
                Map<AbMenuItem, AbMenuItem> map3 = new HashMap<AbMenuItem, AbMenuItem>();
                Map<AbMenuItem, AbMenuItem> map4 = new HashMap<AbMenuItem, AbMenuItem>();
                Map<AbMenuItem, AbMenuItem> map5 = new HashMap<AbMenuItem, AbMenuItem>();
                Map<AbMenuItem, AbMenuItem> map6 = new HashMap<AbMenuItem, AbMenuItem>();
                Map<AbMenuItem, AbMenuItem> map7 = new HashMap<AbMenuItem, AbMenuItem>();
                Map<AbMenuItem, AbMenuItem> map8 = new HashMap<AbMenuItem, AbMenuItem>();
                map1.put(new AbMenuItem("申请到货日期："), new AbMenuItem(qgds.getDdate_dh()));
                map2.put(new AbMenuItem("    自定义项二："), new AbMenuItem(qgds.getCdefine2()));
                map3.put(new AbMenuItem("    自定义项三："), new AbMenuItem(qgds.getCdefine3()));
                map4.put(new AbMenuItem("　        现存量："), new AbMenuItem(qgds.getIlquantity()));
                map5.put(new AbMenuItem("　    上月用量："), new AbMenuItem(qgds.getAvgiquantity()));
                map6.put(new AbMenuItem("　    最近入库："), new AbMenuItem(qgds.getDdate()));
                map7.put(new AbMenuItem("　    最近单价："), new AbMenuItem(qgds.getIlprice()));
                map8.put(new AbMenuItem("　最近供应商："), new AbMenuItem(qgds.getClvencode()));
                ArrayList<Map<AbMenuItem, AbMenuItem>> data = new ArrayList<Map<AbMenuItem, AbMenuItem>>();
                data.add(map1);
                data.add(map2);
                data.add(map3);
                data.add(map4);
                data.add(map5);
                data.add(map6);
                data.add(map7);
                data.add(map8);
                ListPopAdapter mListPopAdapter = new ListPopAdapter(qgddj_detail.this, data, R.layout.list_popitem);
                popListView.setAdapter(mListPopAdapter);
                //弹出窗口后,变更更多图标
                imgs.setImageResource(R.drawable.item_more_choose);
                popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                    public void onDismiss() {
                        //还原图标
                        imgs.setImageResource(R.drawable.item_more);
                    }
                });
                popupWindow.showAsDropDown(v);
            }
        });
    }

    //供应商选择
    public void cven_choose(View v) {
        String btntype = v.getTag().toString();
        String cvencode = "";
        if (btntype.equals("cven")) {
            cvencode = cven_tv.getTag().toString();
        } else if (btntype.equals("cven1")) {
            cvencode = cven1_et.getTag().toString();
        } else if (btntype.equals("cven2")) {
            cvencode = cven2_et.getTag().toString();
        } else {
            cvencode = cven3_et.getTag().toString();
        }
        Intent intent = new Intent(getApplicationContext(), Basenvo_Choosecven.class);
        // 设置传递数据
        intent.putExtra("btntype", btntype);
        intent.putExtra("ccode", cvencode);
        startActivityForResult(intent, R.layout.basenvo_rchoose / 200000);
    }

    //存货切换
    public void more_list(View v) {
        //刷新修改列的值
        updatedataref();
        Intent intent = new Intent(getApplicationContext(), qgddj_detaillist.class);
        //传递参数
        Bundle bundle = new Bundle();
        intent.putExtra("cinvcode", qgds.getCinvcode());//当前存货编码
        intent.putExtra("currentrow", "" + icurrentrow);//当前存货行号
        bundle.putSerializable("detaillist", qgdlist_detail);//存货明细列表
        bundle.putSerializable("qgdtitle", qgdtitle);//单据表头
        bundle.putSerializable("listtype", listtype);//未定价/已定价
        intent.putExtras(bundle);
        startActivityForResult(intent, R.layout.layout_qgddj_detaillist / 300000);
    }

    public void showwin(boolean stype) {
        //背景变白，字变黑色
        iquantity_tv.setEnabled(stype);
        cven_tv.setEnabled(stype);
        iprice_et.setEnabled(stype);
        cven1_et.setEnabled(stype);
        iprice1_et.setEnabled(stype);
        cven2_et.setEnabled(stype);
        iprice2_et.setEnabled(stype);
        cven3_et.setEnabled(stype);
        iprice3_et.setEnabled(stype);
        if (stype) {
            //iquantity_tv.setBackgroundResource(R.drawable.edit_background);
            iquantity_tv.setBackgroundResource(R.drawable.edit_background);
            cven_tv.setBackgroundResource(R.drawable.edit_background);
            iprice_et.setBackgroundResource(R.drawable.edit_background);
            cven1_et.setBackgroundResource(R.drawable.edit_background);
            iprice1_et.setBackgroundResource(R.drawable.edit_background);
            cven2_et.setBackgroundResource(R.drawable.edit_background);
            iprice2_et.setBackgroundResource(R.drawable.edit_background);
            cven3_et.setBackgroundResource(R.drawable.edit_background);
            iprice3_et.setBackgroundResource(R.drawable.edit_background);

        } else {
            int textcolor = textcolor_old;
            Integer backgroundcolor = Color.TRANSPARENT;

            iquantity_tv.setTextColor(textcolor);
            iquantity_tv.setBackgroundColor(backgroundcolor);

            cven_tv.setTextColor(textcolor);
            cven_tv.setBackgroundColor(backgroundcolor);

            iprice_et.setTextColor(textcolor);
            iprice_et.setBackgroundColor(backgroundcolor);

            //iamount_tv.setEnabled(stype);
            //iamount_tv.setTextColor(textcolor);
            //iamount_tv.setBackgroundColor(backgroundcolor);

            cven1_et.setTextColor(textcolor);
            cven1_et.setBackgroundColor(backgroundcolor);

            iprice1_et.setTextColor(textcolor);
            iprice1_et.setBackgroundColor(backgroundcolor);

            cven2_et.setTextColor(textcolor);
            cven2_et.setBackgroundColor(backgroundcolor);

            iprice2_et.setTextColor(textcolor);
            iprice2_et.setBackgroundColor(backgroundcolor);

            cven3_et.setTextColor(textcolor);
            cven3_et.setBackgroundColor(backgroundcolor);


            iprice3_et.setTextColor(textcolor);
            iprice3_et.setBackgroundColor(backgroundcolor);
        }
        //编辑和完成图标的切换，编辑图标不在需要
        //ImageView editover_iv = (ImageView) findViewById(R.id.editover_iv);
        //ImageView edit_iv = (ImageView) findViewById(R.id.edit_iv);
        if (stype) {
            cven_iv.setVisibility(View.VISIBLE);
            cven_iv1.setVisibility(View.VISIBLE);
            cven_iv2.setVisibility(View.VISIBLE);
            cven_iv3.setVisibility(View.VISIBLE);
            // editover_iv.setVisibility(View.VISIBLE);
            // edit_iv.setVisibility(View.GONE);
        } else {
            cven_iv.setVisibility(View.GONE);
            cven_iv1.setVisibility(View.GONE);
            cven_iv2.setVisibility(View.GONE);
            cven_iv3.setVisibility(View.GONE);
            // editover_iv.setVisibility(View.GONE);
            // edit_iv.setVisibility(View.VISIBLE);
        }

    }

    //对一些修改后的值进行处理,避免因为没触发事件导致保存的信息不正确
    public void updatedataref() {
        String iquantity = iquantity_tv.getText().toString();
        String iprice = iprice_et.getText().toString();
        if (iquantity == null || iquantity.equals("") || iprice.equals("")) {
            iamount_tv.setText(Basenvo.customFormat("#####0.00##", "0"));
        } else {
            iamount_tv.setText(Basenvo.customFormat("#####0.00##", Double.valueOf(iquantity) * Double.valueOf(iprice)));
        }
        String cvenlistrow = null;
        //更新供应商待选1
        cvenlistrow = Basenvo.venlistfind(venlist, cven1_et.getText().toString());
        if (cvenlistrow != null) {
            cven1_et.setTag(venlist.get(Integer.valueOf(cvenlistrow)).getCvenCode());
        } else {
            cven1_et.setTag("");
        }
        //更新供应商待选2
        cvenlistrow = Basenvo.venlistfind(venlist, cven2_et.getText().toString());
        if (cvenlistrow != null) {
            cven2_et.setTag(venlist.get(Integer.valueOf(cvenlistrow)).getCvenCode());
        } else {
            cven2_et.setTag("");
        }
        //更新供应商待选1
        cvenlistrow = Basenvo.venlistfind(venlist, cven3_et.getText().toString());
        if (cvenlistrow != null) {
            cven3_et.setTag(venlist.get(Integer.valueOf(cvenlistrow)).getCvenCode());
        } else {
            cven3_et.setTag("");
        }
        //保存修改内容
        if (iquantity_tv.getText() != null) {
            qgds.setIquantity(iquantity_tv.getText().toString());
        } else {
            qgds.setIquantity("");
        }

        if (cven_tv.getTag() != null) {
            qgds.setCvencode(cven_tv.getTag().toString());
            qgds.setCvenname(cven_tv.getText().toString());
        } else {
            qgds.setCvencode("");
            qgds.setCvenname("");
        }

        if (iprice_et.getText() != null) {
            qgds.setIprice(iprice_et.getText().toString());
        } else {
            qgds.setIprice("");
        }
        if (iamount_tv.getText() != null) {
            qgds.setIamount(iamount_tv.getText().toString());
        } else {
            qgds.setIamount("");
        }
        if (cven1_et.getTag() != null) {
            qgds.setCvencodep1(cven1_et.getTag().toString());
            qgds.setCvennamep1(cven1_et.getText().toString());
        } else {
            qgds.setCvencodep1("");
            qgds.setCvennamep1("");
        }

        if (iprice1_et.getText() != null) {
            qgds.setIpricep1(iprice1_et.getText().toString());
        } else {
            qgds.setIpricep1("");
        }
        if (cven2_et.getTag() != null) {
            qgds.setCvencodep2(cven2_et.getTag().toString());
            qgds.setCvennamep2(cven2_et.getText().toString());
        } else {
            qgds.setCvencodep2("");
            qgds.setCvennamep2("");
        }

        if (iprice2_et.getText() != null) {
            qgds.setIpricep2(iprice2_et.getText().toString());
        } else {
            qgds.setIpricep2("");
        }

        if (cven3_et.getTag() != null) {
            qgds.setCvencodep3(cven3_et.getTag().toString());
            qgds.setCvennamep3(cven3_et.getText().toString());
        } else {
            qgds.setCvencodep3("");
            qgds.setCvennamep3("");
        }

        if (iprice3_et.getText() != null) {
            qgds.setIpricep3(iprice3_et.getText().toString());
        } else {
            qgds.setIpricep3("");
        }
        //是否通过
        RadioButton yes_rb = (RadioButton) findViewById(R.id.yes_rb);
        if (yes_rb.isChecked()) {
            qgds.setBapprove("1");
        } else {
            qgds.setBapprove("0");
        }
    }

    //请购单协议定价
    public void qgddj_xy(View v) {
        if (!preeditcheck()) {
            AbDialogUtil.removeDialog(qgddj_detail.this);
            return;
        }

        String urlString = "http://" + InstorageURL.SERVERURL + BaseUrl_New;//旧版webservice地址
        String[] parms = {"cacc_id", "iyear", "ddate_qg"};
        String[] vals = {(String) myApplication.getGs_ztid(), (String) myApplication.getGs_year(), qgdtitle.getDdate()};
        //生成xml
        BuildQgdDjdetailXMLService service = new BuildQgdDjdetailXMLService();
        String xmlstring = service.buildXML(qgdlist_detail, "qgddj_xy", InstorageURL.NAME_SPACE, parms, vals, "in" + vals.length);
        mAbSoapUtil.xmlCall(urlString, InstorageURL.NAME_SPACE, "qgddj_xy", xmlstring, new AbSoapUtil.WebServiceCallBack() {
            @Override
            public void onSucced(String result) {
                if (result != null) {
                    //解析xml文件,返回列表
                    qgdlist_detail = XMLQgdDjdetail.paraseCommentInfors(result);
                    //默认显示第一行数据
                    if (qgdlist_detail.size() > 0) {
                        insert_data(0);
                        AbToastUtil.showToastInThread(getApplicationContext(), "请购单协议定价完成!");
                    }
                } else {
                    AbToastUtil.showToastInThread(getApplicationContext(), "请购单协议定价失败!数据库错误!");
                }
                AbDialogUtil.removeDialog(qgddj_detail.this);
            }

            @Override
            public void onFailure(String result) {
                AbToastUtil.showToastInThread(getApplicationContext(), "请购单协议定价失败!");
                AbDialogUtil.removeDialog(qgddj_detail.this);
            }
        });
    }

    //请购单历史信息定价
    public void qgddj_his(View v) {
        if (!preeditcheck()) {
            AbDialogUtil.removeDialog(qgddj_detail.this);
            return;
        }

        AbDialogUtil.showProgressDialog(qgddj_detail.this, 0, "正在加载...");
        String urlString = "http://" + InstorageURL.SERVERURL + BaseUrl_New;//旧版webservice地址
        String[] parms = {"cacc_id", "iyear"};
        String[] vals = {(String) myApplication.getGs_ztid(), (String) myApplication.getGs_year()};
        //生成xml
        BuildQgdDjdetailXMLService service = new BuildQgdDjdetailXMLService();
        String xmlstring = service.buildXML(qgdlist_detail, "qgddj_his", InstorageURL.NAME_SPACE, parms, vals, "in" + vals.length);
        mAbSoapUtil.xmlCall(urlString, InstorageURL.NAME_SPACE, "qgddj_his", xmlstring, new AbSoapUtil.WebServiceCallBack() {
            @Override
            public void onSucced(String result) {
                if (result != null) {
                    //解析xml文件,返回列表
                    qgdlist_detail = XMLQgdDjdetail.paraseCommentInfors(result);
                    //默认显示第一行数据
                    if (qgdlist_detail.size() > 0) {
                        insert_data(0);
                        AbToastUtil.showToastInThread(getApplicationContext(), "请购单历史信息定价完成!");
                    }
                } else {
                    AbToastUtil.showToastInThread(getApplicationContext(), "请购单历史信息定价失败!数据库错误!");
                }
                AbDialogUtil.removeDialog(qgddj_detail.this);
            }

            @Override
            public void onFailure(String result) {
                AbToastUtil.showToastInThread(getApplicationContext(), "请购单历史信息定价失败!");
                AbDialogUtil.removeDialog(qgddj_detail.this);
            }
        });
    }

    //请购单定价保存
    public void qgddj_save(View v) {
        //刷新修改列的值
        updatedataref();
        if (!preeditcheck()) {
            return;
        }
        //逐行检查明细数据是否存在问题
        for (int i = 0; i < qgdlist_detail.size(); i++) {
            UffjqgdList_detail qgds = qgdlist_detail.get(i);
            if (!qgds.getBclose().equals("1") && !qgds.getBapprove().equals("0")) {
                //检查供应商
                if (qgds.getCvencode().equals("")) {
                    AbToastUtil.showToastInThread(getApplicationContext(), "第" + String.valueOf((i + 1)) + "行的供应商不能为空!");
                    return;
                }
                //检查单价
                if (qgds.getIprice().equals("")) {
                    AbToastUtil.showToastInThread(getApplicationContext(), "第" + String.valueOf((i + 1)) + "行的单价不能为空!");
                    return;
                }
            }
        }

        AbDialogUtil.showProgressDialog(qgddj_detail.this, 0, "正在加载...");
        String urlString = "http://" + InstorageURL.SERVERURL + BaseUrl_New;
        String[] parms = {"user", "cacc_id", "iyear", "cvouchid", "charname", "stepall", "linecode", "istep"};
        String[] vals = {User.nickName, (String) myApplication.getGs_ztid(), (String) myApplication.getGs_year(), qgdtitle.getCvouchid(), qgdtitle.getCchar(), qgdtitle.getStepall(), qgdtitle.getCnocheckreason(), qgdtitle.getIinorder()};
        //生成xml
        BuildQgdDjdetailXMLService service = new BuildQgdDjdetailXMLService();
        String xmlstring = service.buildXML(qgdlist_detail, "qgddj_save", InstorageURL.NAME_SPACE, parms, vals, "in" + vals.length);
        mAbSoapUtil.xmlCall(urlString, InstorageURL.NAME_SPACE, "qgddj_save", xmlstring, new AbSoapUtil.WebServiceCallBack() {
            @Override
            public void onSucced(String result) {
                if (result != null) {
                    //解析xml文件,返回列表
                    qgdlist_detail = XMLQgdDjdetail.paraseCommentInfors(result);
                    //默认显示第一行数据
                    if (qgdlist_detail.size() > 0) {
                        insert_data(0);
                        String succount = qgdlist_detail.get(0).getSuccount();
                        if (succount.equals("0")) {
                            AbToastUtil.showToastInThread(getApplicationContext(), "请购单定价保存失败!");
                        } else if (succount.equals("-101") || succount.equals("-201")) {
                            AbToastUtil.showToastInThread(getApplicationContext(), "您没有这一步审批角色的权限，不能操作!");
                        } else if (succount.equals("-102")) {
                            AbToastUtil.showToastInThread(getApplicationContext(), "单据的上一步骤已经被取消审批了，不能继续定价!");
                        } else if (succount.equals("-202")) {
                            AbToastUtil.showToastInThread(getApplicationContext(), "单据的下一步骤已经审批通过了，不能取消定价!");
                        } else if (succount.equals("-203")) {
                            AbToastUtil.showToastInThread(getApplicationContext(), "此请购单已有记录生成了采购订单，不能取消定价!");
                        } else {
                            AbToastUtil.showToastInThread(getApplicationContext(), "请购单定价保存成功!");
                            //成功之后返回主界面并刷新
                            Intent intent = new Intent();
                            intent.putExtra("isref", "1");//是否需要刷新当前列表
                            setResult(R.layout.layout_qgddj_detail / 100000, intent);  //设置返回结果
                            finish();
                        }
                    }
                } else {
                    AbToastUtil.showToastInThread(getApplicationContext(), "请购单定价保存失败!数据库错误!");
                }
                AbDialogUtil.removeDialog(qgddj_detail.this);
            }

            @Override
            public void onFailure(String result) {
                AbToastUtil.showToastInThread(getApplicationContext(), "请购单定价保存失败!");
                AbDialogUtil.removeDialog(qgddj_detail.this);
            }
        });
    }

    //请购单暂存
    public void qgddj_tempsave(View v) {
        //刷新修改列的值
        updatedataref();
        if (!preeditcheck()) {
            return;
        }

        AbDialogUtil.showProgressDialog(qgddj_detail.this, 0, "正在加载...");
        String urlString = "http://" + InstorageURL.SERVERURL + BaseUrl_New;
        String[] parms = {"user", "cacc_id", "iyear", "cvouchid", "charname"};
        String[] vals = {User.nickName, (String) myApplication.getGs_ztid(), (String) myApplication.getGs_year(), qgdtitle.getCvouchid(), qgdtitle.getCchar()};
        //生成xml
        BuildQgdDjdetailXMLService service = new BuildQgdDjdetailXMLService();
        String xmlstring = service.buildXML(qgdlist_detail, "qgddj_tempsave", InstorageURL.NAME_SPACE, parms, vals, "in" + vals.length);
        mAbSoapUtil.xmlCall(urlString, InstorageURL.NAME_SPACE, "qgddj_tempsave", xmlstring, new AbSoapUtil.WebServiceCallBack() {
            @Override
            public void onSucced(String result) {
                if (result != null) {
                    //解析xml文件,返回列表
                    qgdlist_detail = XMLQgdDjdetail.paraseCommentInfors(result);
                    //默认显示第一行数据
                    if (qgdlist_detail.size() > 0) {
                        insert_data(0);
                        String succount = qgdlist_detail.get(0).getSuccount();
                        if (succount.equals("0")) {
                            AbToastUtil.showToastInThread(getApplicationContext(), "请购单定价暂存失败!");
                        } else {
                            AbToastUtil.showToastInThread(getApplicationContext(), "请购单暂存成功!");
                        }
                    }
                } else {
                    AbToastUtil.showToastInThread(getApplicationContext(), "请购单定价暂存失败!数据库错误!");
                }
                AbDialogUtil.removeDialog(qgddj_detail.this);
            }

            @Override
            public void onFailure(String result) {
                AbToastUtil.showToastInThread(getApplicationContext(), "请购单暂存失败!");
                AbDialogUtil.removeDialog(qgddj_detail.this);
            }
        });
    }

    //有定价人时的反定价操作
    public void qgddj_undj(View v) {
        if (!preeditcheck()) {
            return;
        }

        AbDialogUtil.showProgressDialog(qgddj_detail.this, 0, "正在加载...");
        String urlString = "http://" + InstorageURL.SERVERURL + BaseUrl_New;
        String[] parms = {"user", "cacc_id", "iyear", "cvouchid", "charname", "stepall", "linecode", "istep"};
        String[] vals = {User.nickName, (String) myApplication.getGs_ztid(), (String) myApplication.getGs_year(), qgdtitle.getCvouchid(), qgdtitle.getCchar(), qgdtitle.getStepall(), qgdtitle.getCnocheckreason(), qgdtitle.getCdefine4()};//取消定价的步骤
        //生成xml
        BuildQgdDjdetailXMLService service = new BuildQgdDjdetailXMLService();
        String xmlstring = service.buildXML(qgdlist_detail, "qgddj_undj", InstorageURL.NAME_SPACE, parms, vals, "in" + vals.length);
        mAbSoapUtil.xmlCall(urlString, InstorageURL.NAME_SPACE, "qgddj_undj", xmlstring, new AbSoapUtil.WebServiceCallBack() {
            @Override
            public void onSucced(String result) {
                if (result != null) {
                    //解析xml文件,返回列表
                    qgdlist_detail = XMLQgdDjdetail.paraseCommentInfors(result);
                    //默认显示第一行数据
                    String succount = qgdlist_detail.get(0).getSuccount();
                    if (succount.equals("0")) {
                        AbToastUtil.showToastInThread(getApplicationContext(), "请购单定价取消失败!");
                    } else {
                        AbToastUtil.showToastInThread(getApplicationContext(), "请购单取消成功!");
                        //取消定价完成应该是关闭当前页面返回到上层
                        Intent intent = new Intent();
                        intent.putExtra("isref", "1");//是否需要刷新当前列表
                        setResult(R.layout.layout_qgddj_detail / 100000, intent);  //设置返回结果
                        finish();
                    }
                } else {
                    AbToastUtil.showToastInThread(getApplicationContext(), "请购单定价取消失败!数据库错误!");
                }
                AbDialogUtil.removeDialog(qgddj_detail.this);
            }

            @Override
            public void onFailure(String result) {
                AbToastUtil.showToastInThread(getApplicationContext(), "请购单定价保存失败!");
                AbDialogUtil.removeDialog(qgddj_detail.this);
            }
        });
    }

    public boolean preeditcheck() {
        if (!qgdtitle.getCchecker().equals("")) {
            AbToastUtil.showToastInThread(getApplicationContext(), "此单据已被审核，不能修改，请取消审核后再试!");
            return false;
        }
        if (((!qgdtitle.getCprechecker().equals(User.nickName) && !qgdtitle.getCprechecker().equals("")) || (!qgdtitle.getCprecheckertemp().equals(User.nickName) && !qgdtitle.getCprecheckertemp().equals(""))) && (!myApplication.getGs_option2().getQgd_dd_check().equals("Y"))) {
            AbToastUtil.showToastInThread(getApplicationContext(), "不能修改他人定价的单据!");
            return false;
        }
        return true;
    }

    //接收返回数据(供应商和存货明细)
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        switch (resultCode) {
            case R.layout.basenvo_rchoose / 200000:
                if (data != null) {
                    //刷新list
                    venlist = myApplication.getGv_vendor();
                    Bundle bundle = data.getExtras();
                    String cvencode = bundle.getString("cvencode");
                    String cvenname = bundle.getString("cvenname");
                    String btntype = bundle.getString("btntype");
                    if (btntype.equals("cven")) {
                        //供应商则必须从列表中获取.
                        cven_tv.setText(cvenname);
                        cven_tv.setTag(cvencode);
                        qgds.setCvencode(cvencode);
                        qgds.setCvenname(cvenname);
                    } else if ((btntype.equals("cven1"))) {
                        cven1_et.setText(cvenname);
                        cven1_et.setTag(cvencode);
                        qgds.setCvencodep1(cvencode);
                        qgds.setCvennamep1(cvenname);
                    } else if ((btntype.equals("cven2"))) {
                        cven2_et.setText(cvenname);
                        cven2_et.setTag(cvencode);
                        qgds.setCvencodep2(cvencode);
                        qgds.setCvennamep2(cvenname);
                    } else if ((btntype.equals("cven3"))) {
                        cven3_et.setText(cvenname);
                        cven3_et.setTag(cvencode);
                        qgds.setCvencodep3(cvencode);
                        qgds.setCvennamep3(cvenname);
                    }
                }
                break;
            case R.layout.layout_qgddj_detaillist / 300000:
                Bundle bundle = data.getExtras();
                String listrow = bundle.getString("listrow");
                if (listrow.equals("-100")) {
                    //退回成功,关闭当前,并刷新列表
                    Intent intent = new Intent();
                    intent.putExtra("isref", "1");//是否需要刷新当前列表
                    setResult(1, intent);  //设置返回结果
                    this.finish();
                } else {
                    //更换明细
                    qgdlist_detail = (ArrayList<UffjqgdList_detail>) data.getSerializableExtra("detaillist");
                    qgdtitle = (UffjqgdList) data.getSerializableExtra("qgdtitle");
                    insert_data(Integer.valueOf(listrow));
                }
            default:
                //其它窗口的回传数据
                break;
        }
        super.onActivityResult(requestCode, resultCode, data);
    }

    //向左翻页
    public void btn_abs_back(View v) {
        updatedataref();
        if (icurrentrow == 0) {
            AbToastUtil.showToastInThread(getApplicationContext(), "已经是第一项!");
        } else {
            insert_data(icurrentrow - 1);
        }
    }

    //向右翻页
    public void btn_abs_forward(View v) {
        updatedataref();
        if (icurrentrow == (qgdlist_detail.size() - 1)) {
            AbToastUtil.showToastInThread(getApplicationContext(), "已经是最后一项!");
        } else {
            insert_data(icurrentrow + 1);
        }
    }
}
